package com.lifa.controller;

import com.lifa.dao.TaocanDao;
import com.lifa.entity.Taocan;
import com.lifa.service.TaocanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/taocan")
@Scope("prototype")
public class TaocanController {
    @Autowired
    private TaocanDao taocanDao;
    @Autowired
    private TaocanService taocanService;

    /**
     * 根据taocan_Id删除套餐信息
     * @param taocan_Id
     * @return
     */
    @RequestMapping("/shanchu")
    @ResponseBody
    public int shanchu(int taocan_Id){
        return taocanService.delete(taocan_Id);
    }

    /**
     * 添加套餐
     * @param taocan
     * @return
     */
    @RequestMapping("/insert")
    @ResponseBody
    public int insert(Taocan taocan){
        return taocanService.adadd(taocan);
    }

    /**
     * 查询全部
     * @return
     */
    @RequestMapping("/tao")
    @ResponseBody
    public List<Taocan> list(){
        return taocanDao.query();
    }
    @RequestMapping("/tao1")
    @ResponseBody
    public List<Taocan> list1(){
        return taocanDao.query();
    }

    /**
     * 模糊加分页
     * @param name
     * @param offset
     * @param limit
     * @return
     */
    @RequestMapping("/queryByName")
    @ResponseBody
    public Map<String,Object> queryPageByName(String name,int offset,int limit){
        Map<String,Object> map = new HashMap<>() ;
        map.put("rows",taocanDao.queryPage(name,offset,limit)) ;
        map.put("total",taocanDao.getTotalCount(name)) ;
        return  map ;
    }
}
